package com.qfedu.yuxiaoer.controller;

import com.qfedu.yuxiaoer.common.api.CommonResult;
import com.qfedu.yuxiaoer.entity.MyApartment;
import com.qfedu.yuxiaoer.service.MyApartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@Api(tags = "MyApartmentController",description = "我的公寓")
@RequestMapping("/myApartment")
public class MyApartmentController {

    @Autowired
    private MyApartmentService myApartmentService;

    @ApiOperation(value = "根据编号公寓信息")
    @RequestMapping(value = "/find/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<MyApartment> findMyApartment(@PathVariable Integer id){
        return CommonResult.success(myApartmentService.selectMyApartment(id));
    }

    @ApiOperation(value = "根据编号编辑公寓信息")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.PUT)
    @ResponseBody
    public CommonResult update(MyApartment myApartment){
        int count = myApartmentService.update(myApartment);
        if (count > 0){
            return CommonResult.success("更新成功");
        }
        return CommonResult.failed();
    }
}